package compiler.nonterminals;

import compiler.HowlToken;
import compiler.HowlType;
import compiler.TokenReader;
import compiler.exceptions.HowlParserException;
import compiler.terminals.FeedName;

/**
 * This class represents delete statements, as in:
 * 
 * delete FeedName
 * 
 * @author Sarah Mount <s.mount@wlv.ac.uk>
 * @version 16 Dec 2009
 * @see compiler.terminals.FeedName
 */
public class DeleteStmt extends HowlToken {

	private FeedName feedname;

	public DeleteStmt(TokenReader tokenReader) {
		super(tokenReader);
	}

	@Override
	public String codeGenerate() {
		return "DELETE * FROM " + this.feedname.codeGenerate() + ";";
	}

	@Override
	public HowlToken parse() throws HowlParserException {
		String command = this.tokenReader.consumeToken();
		if (!"delete".equals(command))
			throw new HowlParserException(this.tokenReader.getStatement(),
					this.tokenReader.getCharNo());
		this.feedname = (FeedName) new FeedName(this.tokenReader).parse();
		return this;
	}

	@Override
	public String toString() {
		return "delete " + this.feedname.toString() + ";";
	}

	/**
	 * @return the feedname
	 */
	public FeedName getFeedname() {
		return feedname;
	}

	/**
	 * @param feedname the feedname to set
	 */
	public void setFeedname(FeedName feedname) {
		this.feedname = feedname;
	}

}
